package com.three.work.serviceImpl;
import com.three.work.bean.result.AppuserPost;
import com.three.work.controller.helper.$;
import com.three.work.bean.Appuser;
import com.three.work.mapper.AppuserMapper;
import com.three.work.service.AppuserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.three.work.bean.result.ResultPage;
import com.three.work.controller.model.ApiResultModel;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 张子艺
 * @since 2020-04-02
 */
@Service
public class AppuserServiceImpl extends ServiceImpl<AppuserMapper, Appuser> implements AppuserService {
    /** 添加Appuser
     * @param appuser  前端传进的参数
     * @return 返回统一信息
     */
    @Override
    public ApiResultModel addAppuser(Appuser appuser  ) {
           if(this.save(appuser )){
               return $.success();
           }else{
                return $.error("添加失败");
           }
    }
    /** 编辑跳转页面的回显数据Appuser
     * @param id  前端传进的参数
     * @return 返回实体类
     */
    @Override
    public Appuser selectAppuserByIdAppuser(Integer id ){
            return this.getById(id);
    }


    /** 编辑Appuser
     * @param appuser  前端传进的参数
     * @return 返回统一信息
     */
    @Override
    public ApiResultModel editAppuser(Appuser appuser  ) {
           if(this.updateById(appuser )){
               return $.success();
           }else{
                return $.error("编辑失败");
           }
    }
    /** 删除一条Appuser
     * @param id  前端传进的ID
     * @return 返回统一信息
     */
    @Override
    public   ApiResultModel delAppuser( Integer id  ){
           if(this.removeById(id)){
               return $.success();
           }else{
                return $.error("删除失败");
           }
    }

   /** 分页查询Appuser
     * @param page  页码
     * @param limit  查几条
     * @param appuser  前端传进的参数
     * @return 返回统一分页信息
     */
    @Override
    public  ResultPage findAppuserByPage(Integer page, Integer limit,Appuser appuser){
        Map<String, Object> paramMap = new HashMap<>();
        paramMap.put("page", (page - 1) * limit);
        paramMap.put("limit", limit);
        paramMap.put("appuser", appuser);
        List<Appuser> list = baseMapper.selectMyPage(paramMap);
        Integer count = baseMapper.countMyPage(paramMap);
        ResultPage<Appuser> resultPage = new ResultPage<>();
        resultPage.setCode(0);
        resultPage.setCount(count);
        resultPage.setMsg("成功");
        resultPage.setData(list);
        return resultPage;
    }
    /**
     * 查询审核成功的员工
     * @return
     */
    @Override
    public ResultPage FindGetSuccessUser() {
        List<AppuserPost> data = baseMapper.getSuccessUser();

        ResultPage<AppuserPost> result = new ResultPage<>();
        result.setCode(0);
        result.setCount(data.size());
        result.setData(data);
        result.setMsg("成功");
        return result;
    }

    /**
     * 审核通过
     * @param id
     * @param state
     * @return
     */
    @Override
    public ApiResultModel FindUpdateUnderUser(Integer id,Integer state) {
        //当前端传过来的state是1 通过其他  其他审核失败
         if(baseMapper.updateUnderUser(id,state)>0){
             return $.success();
         };
        return $.error("审核失败");
    }

    /**
     * 查询所有审核中的人
     * @return
     */
    @Override
    public ResultPage FindGetUnderUser() {

        //查询所有状态(state=2)
        List<AppuserPost> data = baseMapper.getUnderUser();
        System.out.println(data);
        ResultPage<AppuserPost> result = new ResultPage<>();
        result.setCode(0);
        result.setCount(data.size());
        result.setData(data);
        result.setMsg("成功");
        return result;



    }
}
